var app = getApp()
var url = app.url
Page({
  data: {
    showLoading: true, // 等待动画
    alarmList: [],
    detailflag: true,
    detailitem: {}
  },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示
    this.queryAlarm()
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  },
  onPullDownRefresh: function () {
    this.setData({ alarmList: [], showLoading: true })
    this.queryAlarm()
  },
  queryAlarm: function () {
    var that = this
    var header = { 'content-type': 'application/x-www-form-urlencoded' }
    var date = new Date();
    let year = date.getFullYear()
    let mon = date.getMonth() + 1
    let day = date.getDate()
    var dateStr = year + '-' + (mon < 10 ? '0' + mon : mon) + '-' + (day < 10 ? '0' + day : day)
    var params = { bdate: dateStr, edate: dateStr }
    var encodingStr = app.ecbEncrypto(params)
    wx.request({
      url: url + '/xywl/appAlarmInfo.htm',
      data: encodingStr,
      method: 'POST',
      header: header,
      success: function (res) {
        var decodingStr = app.ecbDecrypto(res.data)
        var rest = JSON.parse(decodingStr)
        if (rest.res == 0) {
          var deptId = wx.getStorageSync('deptId')
          var dataList = rest.dataList
          var temp = []
          for (var i = 0; i < dataList.length; i++) {
            if (dataList[i].PARENTID == deptId || deptId == 1) {
              temp.push(dataList[i])
            }
          }
          that.setData({ alarmList: temp })
        }
      },
      complete: function () {
        wx.stopPullDownRefresh()
        that.setData({ showLoading: false })
      }
    })
  },
  showDetail: function (e) {
    var item = e.currentTarget.dataset.item
    this.setData({ detailflag: false, detailitem: item })
  },
  hideDetail: function () {
    this.setData({ detailflag: true })
  },
  
});